package com.southminority.ethnic.mapper.heritage;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.southminority.ethnic.pojo.Inheritor;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 传承人Mapper
 * 
 * @author SouthMinority
 */
@Mapper
public interface InheritorMapper extends BaseMapper<Inheritor> {

    /**
     * 根据非遗项目ID查询传承人列表
     * 
     * @param heritageId 非遗项目ID
     * @return 传承人列表
     */
    @Select("SELECT * FROM inheritor WHERE heritage_id = #{heritageId} AND status = 1 ORDER BY create_time ASC")
    List<Inheritor> selectByHeritageId(@Param("heritageId") Long heritageId);

    /**
     * 批量根据非遗项目ID列表查询传承人
     * 
     * @param heritageIds 非遗项目ID列表
     * @return 传承人列表
     */
    @Select("<script>" +
            "SELECT * FROM inheritor WHERE heritage_id IN " +
            "<foreach item='id' collection='heritageIds' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            " AND status = 1 ORDER BY heritage_id ASC, create_time ASC" +
            "</script>")
    List<Inheritor> selectByHeritageIds(@Param("heritageIds") List<Long> heritageIds);
} 
